package com.boc.langxiang.presenter.shop;

import com.boc.langxiang.contract.shop.PayContract;
import com.boc.langxiang.entity.bean.AliPayOrderInfo;
import com.boc.langxiang.entity.request.PayRequest;
import com.boc.langxiang.entity.response.BaseResponse;
import com.boc.langxiang.net.HandleErrorSubscriber;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Li Guoxi on 2016/12/28.
 */

public class PayPresenter implements PayContract, PayContract.Presenter {
    private View mView;

    public PayPresenter(View view) {
        this.mView = view;
    }

    @Override
    public void pay(String orderId, String payWay) {
        mView.showLoading();
        final PayRequest request = new PayRequest(orderId, payWay);
        mService.orderPay(request.params())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<AliPayOrderInfo>>(mView) {
                    @Override
                    public void onSuccess(BaseResponse<AliPayOrderInfo> response) {
                        mView.onGetPayInfoSuccess(response.getContent());
                    }
                });
    }
}
